// PersonTest.java
//
// Informatics 102 Spring 2012
// Code Example
//
// This is a QuickUnit test class, containing QuickUnit test methods.

package quickUnit.inf102.personexample;

import quickUnit.inf102.quickunit.Test;


public class PersonTest
{
	@Test
	public void whenCreatedWithoutAPhoneNumberPersonsHaveNoPhoneNumber()
	{
		Person p = new Person("Alex Thornton");

		// If we get back something other than null, that indicates a
		// test failure, so we'll throw an exception.  It doesn't
		// matter what kind of exception we throw, so we'll throw a
		// bare RuntimeException (so we don't have to say "throws").
		if (p.getPhoneNumber() != null)
		{
			throw new RuntimeException(
				"non-null phone number returned when null was expected");
		}

		// I should point out that there are better ways to do this.  JUnit,
		// for example, includes a variety of assert methods, which throw
		// an AssertionFailedException when they don't have the desired
		// result.  For example, we could write the if statement above
		// this way instead:
		//
		//     assertNull(p.getPhoneNumber());
		//
		// If you'd like to take this example a little further, write a
		// simple assert mechanism like the one provided by JUnit.  It's
		// surprisingly little work -- JUnit has an Assert class with a
		// set of static assert methods, which throw an AssertionError when
		// the assertions fail and have no effect when they succeed.
	}
	
	
	@Test
	public void whenCreatedWithANamePersonsHaveThatName()
	{
		Person p = new Person("Alex Thornton", "949-123-4567");
		String personName = p.getName();

		if (!personName.equals("Alex Thornton"))
		{
			throw new RuntimeException(
				"getName() returned " + personName
				+ "; 'Alex Thornton' expected");
		}
	}
}
